import time

from selenium.webdriver import Firefox
from selenium.webdriver.common.by import By

# 创建浏览器对象
driver = Firefox(executable_path=r'C:\Users\薛国鹏\.wdm\drivers\geckodriver\win64\v0.33.0\geckodriver.exe')

url = 'https://fanyi.youdao.com/'

# 打开url
driver.get(url)
# 获取输入框
input = driver.find_element(By.ID, "js_fanyi_input")
# 输入内容
input.send_keys("hello")

time.sleep(5)
# 获取翻译按钮
# tbtn = driver.find_element(By.CLASS_NAME, "transBtn searchBtn red-button")
# 发现页面被遮挡，此时无法点击
# tbtn.click()
# 先获取遮挡的广告条，点击关闭按钮
# close_btn = driver.find_element(By.CSS_SELECTOR, ".guide-con .guide-close")
# close_btn.click()
# 点击翻译
# tbtn.click()
# 获取翻译后的内容
transTarget = driver.find_element(By.ID, "js_fanyi_output_resultOutput")
print(transTarget.text)
